package com.gjy.mongo.sp;

import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-01-30 11:23:03
 */
@Service
public class PersonService {

    @Resource
    private PersonRepository personRepository;

    @PostConstruct
    public void init() {
//        run();
    }

    private void run() {
        PersonAttrs attrs = new PersonAttrs();
        attrs.put("$name", "hello");
        attrs.put("$phone", "12999201");

        Person build = Person.builder()
                .id("P002")
                .personAttrs(attrs)
                .book(Book.builder()
                        .title("aa")
                        .voteCount(221)
                        .build())
                .build();
        personRepository.save(build);

        System.out.println("personRepository.findById(\"P001\") = " + personRepository.findById("P002"));
    }
}
